package cn.aylog;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import java.io.File;
import java.io.FileReader;
import java.io.IOException;
import java.util.Properties;

@Configuration
public class DbConfig {

    private static String driverClass;
    private static String url;
    private static String username;
    private static String password;

    static {
        Properties props = new Properties();
        try {
            // 获取配置文件路径
            String configPath = System.getProperty("user.home")+ File.separator +"mysql.properties";
            // 加载配置文件
            props.load(new FileReader(configPath));
            driverClass = props.getProperty("driverClass");
            url = props.getProperty("url");
            username = props.getProperty("username");
            password = props.getProperty("password");
        } catch (IOException e) {
            e.printStackTrace();
        }
    }

    @Bean("driverClass")
    public static String getDriverClass() {
        return driverClass;
    }

    @Bean("url")
    public static String getUrl() {
        return url;
    }

    @Bean("username")
    public static String getUsername() {
        return username;
    }

    @Bean("password")
    public static String getPassword() {
        return password;
    }
}
